import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'tabs/home.dart';
import 'tabs/money.dart';
import 'tabs/search.dart';
import 'tabs/myhome.dart';

///自定义底部导航条

class BottomNavigationBarClass extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _BottomNavigationBarClass();
  }
}

class _BottomNavigationBarClass extends State<BottomNavigationBarClass> {
  //注意这个顺序不能乱写,是根据这个来进行排序的
  List _pageList = [Home(),Money(), Search(),Myhome(), ];

//页面索引值
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    //Scaffold 脚手架
    return Scaffold(
      //页面的导航
      appBar: AppBar(
        title: Text("根组件标题"),
      ),
      //
      body: this._pageList[this._currentIndex],

      ///自定义底部导航条
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex,
        //选中索引值[]
        onTap: (int index) {
          setState(() {
            this._currentIndex = index;
          });
          //在控制台打印索引值
          print(index);
        },
        //设置按钮的大小
        iconSize: 25.0,
        //选中后的颜色
        fixedColor: Colors.redAccent,
        ///配置底部可以有多个按钮(如果不设置会显示不出来)
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.account_balance),
            title: Text('首页'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.account_balance_wallet),
            title: Text('钱包'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.ac_unit),
            title: Text('发现'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.account_box),
            title: Text('个人'),
          ),
        ],
      ),
    );
  }
}
